package com.pi.base.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Session公共方法类
 * 
 * @author Administrator
 */
public class SessionUtil {
	/**
	 * 保存Session
	 * 
	 * @param request
	 * @param key
	 * @param value
	 */
	public static void setSessionAttribute(HttpServletRequest request, String key, Object value) {
		request.getSession().setAttribute(key, value);
	}
	
	/**
	 * 删除Session
	 * 
	 * @param request
	 * @param key
	 * @param value
	 */
	public static void removeSessionAttribute(HttpServletRequest request, String key) {
		if (getSessionAttribute(request, key) != null)
			request.getSession().removeAttribute(key);
	}
	
	/**
	 * 获取Session
	 * 
	 * @param request
	 * @param key
	 * @param value
	 */
	public static Object getSessionAttribute(HttpServletRequest request, String key) {
		HttpSession session = request.getSession();
		return session == null ? null : session.getAttribute(key);
	}

}
